﻿//using System;
//using System.IO;
//using System.Security.Cryptography;
//using System.Text;

//namespace Akso.Security
//{
//    //This class is got from http://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp
//    public static class SimpleStringCipher
//    {
//        // This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
//        // This size of the IV (in bytes) must = (keysize / 8).  Default keysize is 256, so the IV must be
//        // 32 bytes long.  Using a 16 character string here gives us 32 bytes when converted to a byte array.
//        private static readonly byte[] InitVectorBytes = Encoding.ASCII.GetBytes("jkE49230Tf093b42");

//        // This constant is used to determine the keysize of the encryption algorithm.
//        private const int Keysize = 256;

//        public const string DefaultPassPhrase = "gsKnGZ041HLL4IM8";

//        public static string Encrypt(string plainText, string passPhrase = DefaultPassPhrase)
//        {
//            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
//            using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
//            {
//                byte[] keyBytes = password.GetBytes(Keysize / 8);
//                using (RijndaelManaged symmetricKey = new RijndaelManaged())
//                {
//                    symmetricKey.Mode = CipherMode.CBC;
//                    using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, InitVectorBytes))
//                    {
//                        using (MemoryStream memoryStream = new MemoryStream())
//                        {
//                            using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
//                            {
//                                cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
//                                cryptoStream.FlushFinalBlock();
//                                byte[] cipherTextBytes = memoryStream.ToArray();
//                                return Convert.ToBase64String(cipherTextBytes);
//                            }
//                        }
//                    }
//                }
//            }
//        }

//        public static string Decrypt(string cipherText, string passPhrase = DefaultPassPhrase)
//        {
//            byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
//            using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
//            {
//                byte[] keyBytes = password.GetBytes(Keysize / 8);
//                using (RijndaelManaged symmetricKey = new RijndaelManaged())
//                {
//                    symmetricKey.Mode = CipherMode.CBC;
//                    using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, InitVectorBytes))
//                    {
//                        using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
//                        {
//                            using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
//                            {
//                                byte[] plainTextBytes = new byte[cipherTextBytes.Length];
//                                int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
//                                return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
//                            }
//                        }
//                    }
//                }
//            }
//        }
//    }
//}